package com.ztf666.articlereview.service.impl;


import com.ztf666.articlereview.entity.Review;
import com.ztf666.articlereview.entity.UserReview;
import com.ztf666.articlereview.mapper.ReviewMapper;
import com.ztf666.articlereview.mapper.UserReviewMapper;
import com.ztf666.articlereview.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author z
 * @date 2022/2/21 下午1:06
 */
@Service
public class ReviewServiceImpl implements ReviewService {
    private ReviewMapper reviewMapper;
    @Autowired
    public void setReviewMapper(ReviewMapper reviewMapper) {
        this.reviewMapper = reviewMapper;
    }
    private UserReviewMapper userReviewMapper;
    @Autowired
    public void setUserReviewMapper(UserReviewMapper userReviewMapper) {
        this.userReviewMapper = userReviewMapper;
    }

    @Override
    public void addReview(Integer userId, Integer aid, Integer pid, String content) {
        int rid=reviewMapper.addReview(aid,pid,content);
        userReviewMapper.addId(userId,rid);
    }

    @Override
    public List<Review> findReview(int aid) {
        List<Review> reviews =reviewMapper.seletcReviewByAid(aid,0);

        return reviews;
    }

    @Override
    public List<Review> findReview(int aid, Integer pid) {
        List<Review> reviews =reviewMapper.seletcReviewByAid(aid,pid);
        return reviews;
    }
}
